import java.io.IOException;
import java.net.ServerSocket;

public class Scan
{
    /**
     * Creates a new Scan with specified params.
     */
    public Scan( )
    {
        
    }
    
    
    /**
     * Naive attempt to determine if a port is currently open or not (in use).
     * @param port
     * @return true port is unused, false port is currently being used
     */
    public static boolean isPortOpen( int port )
    {
        boolean open = false;
        try
        {
            ServerSocket ss = new ServerSocket(port);
            open = ss.isBound();
            ss.close();
        }
        catch(IOException ioe)
        {
            // ignore
        }
        return open;
    }    
    
    public static void main( String[] args ) throws IOException
    {
        for( int i = 1025; i < 65536; i++ )
        {
            if( Scan.isPortOpen( i ) == false )
            {
                System.out.println( "Port " + i + " in use");
            }
        }
    }
    

}
